Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 576 Bytes

Integer Division Result in Decimal in SQL server 5b2f8fc88fce4f43aa5345faf9f500cf.md

File metadata and controls

42 lines (31 loc) · 576 Bytes
title date tags draft summary
Integer Division Result in Decimal in SQL server
2021-09-23
SQL
SQL SERVER
false
Get the Decimal result from deviding Integers in SQL Server

Problem

Get the result in Decimal value by dividing Integer values in SQL Server.

Ex:

SELECT 5/2
--Actual 2
--Expected 2.5

Resolution

Convert to decimal

SELECT CONVERT(decimal(4,2), 5) /2
--2.500000

Multiplying by 1.0 Converts value into numeric

SELECT 5*1.0/2
--2.500000

Shorthand method *1.

SELECT 5*1./2
--2.500000